import axios from 'axios';
import { getAuth } from './storage';

// 请求基地址
export const baseURL = 'https://brand-manage-test.artistnft.com.cn';

// 创建 axios 实例
const request = axios.create({
  baseURL,
  timeout: 5000,
});

// 请求拦截器
request.interceptors.request.use(
  (config: any) => {
    const { token } = getAuth();
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
  },
  (error) => {
    return Promise.reject(error);
  },
);

// 响应拦截器
request.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    return Promise.reject(error);
  },
);

// 导出 axios 实例
export default request;
